package game.JFrame;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JFrameDemo2 extends JFrame {

        JPanel root;
        JLabel unameLabel,upwdLabel;
        JTextField unameText;
        JPasswordField upwd;
        JButton loginBtn,exitBtn;

        public JFrameDemo2(){
            //定义面板容器
            root =new JPanel();
            setContentPane(root);
            setLayout(null);//设置绝对布局

            unameLabel = new JLabel("用户名: ");
            unameLabel.setBounds(52,33,54,15);
            root.add(unameLabel);
            unameText = new JTextField(12);
            unameText.setBounds(116,30,139,21);
            root.add(unameText);
            upwdLabel = new JLabel("密 码: ");
            upwdLabel.setBounds(52,74,54,15);
            root.add(upwdLabel);

            //密码框
            upwd = new JPasswordField(12);
            upwd.setBounds(116,71,139,21);
            //设置回显字符
            upwd.setEchoChar('●');
            root.add(upwd);

            loginBtn = new JButton("登录");
            loginBtn.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String actionCommand = e.getActionCommand();

                    Object source = e.getSource();
                }

                String userName = "hahah";
            });
            loginBtn.setBounds(64,116,69,23);
            root.add(loginBtn);
            exitBtn = new JButton("退出");
            exitBtn.setBounds(174,116,69,23);
            root.add(exitBtn);


            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setBounds(400,300,340,256);
            setVisible(true);

        }

        public static void main(String[] args) {
            new JFrameDemo2();
        }


}
